﻿@using Sovigaz
@{
    ViewBag.Title = "Chi tiết chai";
    var url = Request.Url.Scheme + "://" + Request.Url.Authority + Request.ApplicationPath.TrimEnd('/');
    string vietnamese = "àáạãảắằẵẳặấầậẫẩùúũụủữừứửựòóỏõọớờỡởợốồộổỗèéẻẽẹếềểễệìíỉịĩđ";
    vietnamese += vietnamese.ToUpper(); 
}
<script>
    app.controller('ProductController', function ($scope, $compile, $http, $filter, service) {    
        $scope.load = function () {
            startloading($('#content'));

            var url = '@url' + '@Url.Action("ProductApi", "Api", new { id = Model })';

            $http.get(url)
                .success(function (data) {
                    $scope.product = data;
                    $scope.product.ManufacturedDate = $filter('date')(Date.parse($scope.product.ManufacturedDate), 'y/MM/dd');
                    $scope.product.BoughtDate = $filter('date')(Date.parse($scope.product.BoughtDate), 'y/MM/dd');
                    $scope.product.CheckedDate = $filter('date')(Date.parse($scope.product.CheckedDate), 'y/MM/dd');
                    $scope.product.AssignedDate = $filter('date')(Date.parse($scope.product.AssignedDate), 'y/MM/dd');
                    
                    $scope.lots.length = 0;
                    $scope.lots.push({"name":"-Select One-","value":0});
                    for (var i = 0; i < data.Lots.length; i++) {
                        $scope.lots.push({"name":data.Lots[i].LotCode,"value":data.Lots[i].LotID});
                    }
                    $scope.partners.length = 0;
                    for (var i = 0; i < data.Partners.length; i++) {
                        $scope.partners.push({"name":data.Partners[i].PartnerName,"value":data.Partners[i].PartnerID});
                    }
                    $scope.categories.length = 0;
                    for (var i = 0; i < data.Categories.length; i++) {
                        $scope.categories.push({"name":data.Categories[i].CategoryName,"value":data.Categories[i].CategoryID});
                    }
                    $scope.lotID = { name: '', value: data.LotID };
                    $scope.ownerID = { name: '', value: data.OwnerID };
                    $scope.partnerID = { name: '', value: data.PartnerID };
                    $scope.categoryID = { name: '', value: data.CategoryID };
                    $scope.manufacture = { name: '', value: data.Manufacture };
                    $scope.status = { name: '', value: data.Status };
                    $scope.size = { name: '', value: data.Size };
                    stoploading($('#content'));
                })
                .error(function (data) {
                    stoploading($('#content'));
                    service.showModal($scope, $compile, 'error', data);
                });
        };

        $scope.selectedOwnerChanged = function () {            
            if($scope.ownerID.value==1) $scope.product.Barcode = 'TS' + $scope.product.Barcode.slice(2,$scope.product.Barcode.length);
            else $scope.product.Barcode = 'TC' + $scope.product.Barcode.slice(2,$scope.product.Barcode.length);
        };


        $scope.add = function () {
            window.location = '@Url.Action("Detail", "Product", new { id = String.Empty })';
        };

        $scope.save = function () {
            if($scope.form.$valid)
            {
                $scope.product.Status = $scope.status.value;
                $scope.product.Size = $scope.size.value;
                $scope.product.PartnerID = $scope.partnerID.value;
                $scope.product.OwnerID = $scope.ownerID.value;
                $scope.product.LotID = $scope.lotID.value;
                $scope.product.CategoryID = $scope.categoryID.value;
                $scope.product.Manufacture = $scope.manufacture.value;
                var url = '@url' + '@Url.Action("ProductApi", "Api")';            
                $http.put(url, $scope.product)
                    .success(function(data) {
                        if (@Model === 0) {
                            window.location = '@Url.Action("Detail", "Product")/' + data.ProductID;
                        }
                        $scope.product = data;

                        stoploading($('#content'));
                        service.showModal($scope, $compile, 'notify', 'Dữ liệu đã được lưu thành công!!!');
                    })
                    .error(function(data) {
                        stoploading($('#content'));
                        service.showModal($scope, $compile, 'error', data);
                    });
                }
        };

        $scope.confirmDelete = function () {
            service.showModal($scope, $compile, 'confirm', 'Bạn có chắc chắn muốn xóa dữ liệu?', 'delete()');
        };

        $scope.delete = function () {
            var url = '@url' + '@Url.Action("ProductApi", "Api")';
            $http.delete(url, {
                params: {
                    id: $scope.product.ProductID
                }
            }).success(function (data) {
                stoploading($('#content'));
                window.location = '@Url.Action("Detail", "Product", new { id = String.Empty })';
            }).error(function (data) {
                stoploading($('#content'));
                service.showModal($scope, $compile, 'error', data);
            });
        };

        $scope.back = function () {
            window.location = '@Url.Action("Index", "Product")';
        };

        

        $scope.lots = [{}];
        $scope.partners = [{}];
        $scope.categories = [{}];

        $scope.statuslist = [
            { name: 'Đạt', value: 'D' },
            { name: 'Mất', value: 'M' },
            { name: 'Không Đạt', value: 'K' }
        ];

        $scope.manufactures = [
            { name: 'Trung Quốc', value: 'China' },
            { name: 'Mỹ', value: 'America' }
        ];

        $scope.sizes = [
            { name: 'Lớn', value: 'L' },
            { name: 'Nhỏ', value: 'N' }
        ];
        $scope.isDisabled = true;
        $scope.load();
    });

    $(function () {
        $("[data-toggle=tooltip]").tooltip();
    });
</script>

<div ng-controller="ProductController">
    @Html.Partial("_PageHeader")
    @Html.Partial("_ToolbarDetail")
    <div id="content" class="content row">
        <form role="form" name="form" autocomplete="off">
            <div class="panel-body">
                <div class="col-lg-2">
                    @Html.Partial("Control/_Control_TextBox_Disabled", new Dictionary<string, string>
                    {
                        {"Text", "Barcode"},
                        {"Model", "product.Barcode"},
                        {"Name", "barcode"},
                    })
                </div>
                <div class="col-lg-2">
                    @Html.Partial("Control/_Control_TextBox_Required", new Dictionary<string, string>
                    {
                        {"Text", "Số chai"},
                        {"Model", "product.ProductCode"},
                        {"Name", "productCode"},
                        {"Message", "Mã số chai bắt buộc nhập."},
                        {"MaxLength","15"},
                        {"Input","Number"}
                    })
                </div>
                <div class="col-lg-2">
                    @Html.Partial("Control/_Control_ComboBox", new Dictionary<string, string>
                    {
                        {"Text", "Lô"},
                        {"Model", "lotID"},
                        {"Name", "lotID"},
                        {"Options", "lotID.name for lotID in lots track by lotID.value"}
                    })
                </div>
                <div class="col-lg-2" style="clear: both">
                    <label>Chủ sở hữu</label>
                    <div class="form-group">
                        <select ng-model="ownerID" name="ownerID" class="form-control" ng-options="ownerID.name for ownerID in partners track by ownerID.value" ng-change="selectedOwnerChanged()">
                        </select>
                    </div>
                </div>
                <div class="col-lg-2">
                    @Html.Partial("Control/_Control_ComboBox", new Dictionary<string, string>
                    {
                        {"Text", "Vị trí chai"},
                        {"Model", "partnerID"},
                        {"Name", "partnerID"},
                        {"Options", "partnerID.name for partnerID in partners track by partnerID.value"}
                    })
                </div>
                <div class="col-lg-2">
                    <div class="form-group">
                        <div class="checkbox" style="margin-top: 20px">
                            <label>
                                <input ng-model="product.IsIndemnify" name="isIndemnify" type="checkbox" disabled />Chai bồi thường
                            </label>
                        </div>
                    </div>
                </div>
                <div class="col-lg-8" style="clear: both; border-top: 1px solid lightgray; margin-top: 10px; margin-bottom: 10px">
                    <label>Chế tạo</label>
                </div>
                <div class="col-lg-2" style="clear: both">
                    @Html.Partial("Control/_Control_ComboBox", new Dictionary<string, string>
                    {
                        {"Text", "Nước sản xuất"},
                        {"Model", "manufacture"},
                        {"Name", "manufacture"},
                        {"Options", "manufacture.name for manufacture in manufactures track by manufacture.value"}
                    })
                </div>
                <div class="col-lg-2">
                    @Html.Partial("Control/_Control_TextBox", new Dictionary<string, string>
                    {
                        {"Text", "Ký hiệu"},
                        {"Model", "product.Symbol"},
                        {"Name", "symbol"},
                        {"MaxLength","15"},
                    })
                </div>
                <div class="col-lg-2">
                    @Html.Partial("Control/_Control_Datepicker", new Dictionary<string, string>
                    {
                        {"Text", "Ngày sản xuất"},
                        {"Model", "product.ManufacturedDate"},
                        {"Name", "manufacturedDate"}
                    })
                </div>
                <div class="col-lg-8" style="clear: both; border-top: 1px solid lightgray; margin-top: 10px; margin-bottom: 10px">
                    <label>Thông số kỹ thuật</label>
                </div>
                <div class="col-lg-2" style="clear: both">
                    @Html.Partial("Control/_Control_ComboBox", new Dictionary<string, string>
                    {
                        {"Text", "Loại chai"},
                        {"Model", "categoryID"},
                        {"Name", "categoryID"},
                        {"Options", "categoryID.name for categoryID in categories track by categoryID.value"}
                    })
                </div>
                <div class="col-lg-2">
                    @Html.Partial("Control/_Control_TextBox", new Dictionary<string, string>
                    {
                        {"Text", "Trọng lượng"},
                        {"Model", "product.Weight"},
                        {"Name", "weight"},
                        {"MaxLength","7"},
                        {"Input","Number"}
                    })
                </div>
                <div class="col-lg-2">
                    @Html.Partial("Control/_Control_TextBox", new Dictionary<string, string>
                    {
                        {"Text", "Sức chứa"},
                        {"Model", "product.Capacity"},
                        {"Name", "capacity"},
                        {"MaxLength","7"},
                        {"Input","Number"}
                    })
                </div>
                <div class="col-lg-2">
                    @Html.Partial("Control/_Control_TextBox", new Dictionary<string, string>
                    {
                        {"Text", "Chất xốp"},
                        {"Model", "product.ChatXop"},
                        {"Name", "ChatXop"},
                        {"MaxLength","15"}
                    })
                </div>
                <div class="col-lg-2" style="clear: both">
                    @Html.Partial("Control/_Control_TextBox", new Dictionary<string, string>
                    {
                        {"Text", "Áp suất nạp"},
                        {"Model", "product.PressureLoad"},
                        {"Name", "pressureLoad"},
                        {"MaxLength","7"},
                        {"Input","Number"}
                    })
                </div>
                <div class="col-lg-2">
                    @Html.Partial("Control/_Control_TextBox", new Dictionary<string, string>
                    {
                        {"Text", "Áp suất thử"},
                        {"Model", "product.PressureTest"},
                        {"Name", "pressureTest"},
                        {"MaxLength","7"},
                        {"Input","Number"}
                    })
                </div>
                <div class="col-lg-2">
                    @Html.Partial("Control/_Control_TextBox", new Dictionary<string, string>
                    {
                        {"Text", "Dung tích"},
                        {"Model", "product.Volume"},
                        {"Name", "volume"},
                        {"MaxLength","7"},
                        {"Input","Number"}
                    })
                </div>
                <div class="col-lg-2">
                    @Html.Partial("Control/_Control_ComboBox", new Dictionary<string, string>
                    {
                        {"Text", "Kích thước"},
                        {"Model", "size"},
                        {"Name", "size"},
                        {"Options", "size.name for size in sizes track by size.value"}
                    })
                </div>
                <div class="col-lg-8" style="clear: both; border-top: 1px solid lightgray; margin-top: 10px; margin-bottom: 10px">
                </div>
                <div class="col-lg-2" style="clear: both">
                    @Html.Partial("Control/_Control_Datepicker", new Dictionary<string, string>
                    {
                        {"Text", "Ngày mua/nhập"},
                        {"Model", "product.BoughtDate"},
                        {"Name", "boughtDate"}
                    })
                </div>
                <div class="col-lg-2">
                    @Html.Partial("Control/_Control_Datepicker", new Dictionary<string, string>
                    {
                        {"Text", "Kiểm tra lần đầu"},
                        {"Model", "product.CheckedDate"},
                        {"Name", "checkedDate"}
                    })
                </div>
                <div class="col-lg-2">
                    @Html.Partial("Control/_Control_ComboBox", new Dictionary<string, string>
                    {
                        {"Text", "Tình trạng"},
                        {"Model", "status"},
                        {"Name", "status"},
                        {"Options", "status.name for status in statuslist track by status.value"},
                        {"Disabled","isDisabled"}
                    })
                </div>
                <div class="col-lg-8" style="clear: both">
                    @Html.Partial("Control/_Control_TextArea", new Dictionary<string, string>
                    {
                        {"Text", "Chứng nhận"},
                        {"Model", "product.Certify"},
                        {"Name", "certify"}
                    })
                </div>
                <div class="col-lg-2" style="clear: both">
                    @Html.Partial("Control/_Control_TextBox", new Dictionary<string, string>
                    {
                        {"Text", "Phân bổ cho xí nghiệp"},
                        {"Model", "product.AssignedToEnterprise"},
                        {"Name", "assignedToEnterprise"},
                        {"MaxLength","30"}
                    })
                </div>
                <div class="col-lg-2">
                    @Html.Partial("Control/_Control_Datepicker", new Dictionary<string, string>
                    {
                        {"Text", "Ngày phân bổ"},
                        {"Model", "product.AssignedDate"},
                        {"Name", "assignedDate"}
                    })
                </div>                
                <div class="col-lg-8" style="clear: both">
                    @Html.Partial("Control/_Control_TextArea", new Dictionary<string, string>
                    {
                        {"Text", "Ghi chú"},
                        {"Model", "product.Description"},
                        {"Name", "description"}
                    })
                </div>
            </div>
        </form>
    </div>
</div>
